/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.to.aboomy.bannersample.util;

import com.to.aboomy.banner.BannerViewPager;
import ohos.agp.components.Component;

/**
 * ZoomOutSlideTransformer
 *
 * @since 2021-07-27
 */
public class ZoomOutSlideTransformer implements BannerViewPager.PageTransformer {
    private static final float FLOAT_0_7 = 0.7f;
    private static final float FLOAT_0_5 = 0.5f;

    /**
     * transformerPage
     *
     * @param pageType     BannerViewPager.PageType
     * @param page         Component
     * @param offset       float
     * @param offsetPixels float
     */
    @Override
    public void transformerPage(BannerViewPager.PageType pageType, Component page, float offset, float offsetPixels) {
        float scale = FLOAT_0_7;
        switch (pageType) {
            case PREVIOUS:
                if (offsetPixels <= 0) {
                    scale = FLOAT_0_7 + offset * FLOAT_0_5;
                    if (scale > 1) {
                        scale = 1;
                    }
                }
                break;
            case CURRENT:
                scale = 1 - offset * FLOAT_0_5;
                if (scale < FLOAT_0_7) {
                    scale = FLOAT_0_7;
                }
                break;
            case NEXT:
                if (offsetPixels >= 0) {
                    scale = FLOAT_0_7 + offset * FLOAT_0_5;
                    if (scale > 1) {
                        scale = 1;
                    }
                }
                break;
            default:
        }
        page.setScale(scale, scale);
    }
}

